#ifndef TCPSERVER_H
#define TCPSERVER_H

#include <QWidget>
#include <QTcpServer>
#include <QTcpSocket>

QT_BEGIN_NAMESPACE
namespace Ui { class TcpServer; }
QT_END_NAMESPACE

class TcpServer : public QWidget
{
    Q_OBJECT

public:
    TcpServer(QWidget *parent = nullptr);
    ~TcpServer();

    void initSlotData();

    QString getLocalIP();
private slots:
    //自定义槽函数
    void  onNewConnection();    //QTcpServer的newConnection()信号
    void onSocketStateChanged(QAbstractSocket::SocketState socketState);  //当前socket发生变化
    void onClientConnected();   //有客户端连接过来
    void onClientDisconnected();  //有客户端断开连接
    void onSocketReadyRead();   //读取socket传入的数据

private slots:
    //UI 关联槽函数
    void on_pushButton_startListen_clicked();

    void on_pushButton_sendMsg_clicked();

    void on_pushButton_CleanMsgBox_clicked();

    void on_pushButton_Exit_clicked();

private:
    Ui::TcpServer *ui;

    bool mListenState = false; //false未监听，true开始监听
    QTcpServer * mTcpServer = nullptr; //tcp服务器
    QTcpSocket * mTcpSocket = nullptr; //tcp通信的Socket

};
#endif // TCPSERVER_H
